package jdbc;

import jdbc.common.InputUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class LoginUserDemo {
    public static void main(String[] args) {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"欢迎回来！");
        try(Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();

            String sql = "select id, username, password, nickname, age\n" +
                    "from userinfo\n" +
                    "where username = '"+userInfo.getUsername()+"' and password = '"+userInfo.getPassword()+"'";
            ResultSet rs = statement.executeQuery(sql);


            if(rs.next()){
                System.out.println("登录成功");
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
